/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.tln.sys.role.dao.impl;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.tln.sys.role.dao.RoleDao;
import com.tln.sys.role.model.Role;


import java.util.List;

@Repository("roleDao")
@SuppressWarnings("unchecked")
public class RoleDaoImpl extends com.xjj.core.modules.orm.hibernate.HibernateDao<Role, Long> implements RoleDao {
	
	private static final Logger logger = LoggerFactory.getLogger(RoleDaoImpl.class); 

    /*public Role getRole(Long RoleId) {
        return (Role)super.get(RoleId);//(Role) getSession().get(Role.class, RoleId);
    }*/

    public Role findRole(String Rolename) {
        Assert.hasText(Rolename);
        String query = "from Role u where u.Rolename = :Rolename";
        return (Role) getSession().createQuery(query).setString("Rolename", Rolename).uniqueResult();
    }

   /* public void saveRole(Role Role) {
        getSession().save( Role );
    }*/

    public List<Role> getAllRoles() {
    	logger.info("getAllRoles..........................");
    	logger.info("***********************1*************");
    	//List list = this.findAll();
    	//logger.info("***********************2*************"+list.size());
    	logger.info("************************3************");
    	List list = getSession().createQuery("from Role order by Rolename").list();
    	logger.info("size--- "+list.size());
    	logger.info("***********************4*************");
        return list;
    }

    /*public void deleteRole(Long RoleId) {
        Role Role = getRole(RoleId);
        if( Role != null ) {
            getSession().delete(Role);
        }
    }

    public void updateRole(Role Role) {
        getSession().update(Role);
    }*/
    
    
    public List find(String hql) {
		return super.find(hql);
	}
    
    public Role getRole(Long id) {
		return super.get(id);
	}

}

